<template>
  <div class="app-container">
    <el-col :span="18" :offset="3" :xs="24">
      <el-card class="Empl_entry_edit" v-if="editFlag">
        <div slot="header" class="clearfix">
          <span>入职办理申请</span>
        </div>
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="申请日期" prop="applyDate">
                <span>{{ form.applyDate }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="申请人" prop="applyPartyId">
                <span>{{ partyIdFormat(form) }}</span>
              </el-form-item>
            </el-col>
            <el-row>
            </el-row>
            <el-col :span="12">
              <el-form-item label="员工编号" prop="partyId">
                <span>{{ form.partyId }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider content-position="center">员工信息</el-divider>
          <el-row>
            <el-col :span="12">
              <el-form-item label="姓名" prop="firstName">
                <el-input v-model="form.firstName" placeholder="请输入姓名" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="性别">
                <el-radio-group v-model="form.gender">
                  <el-radio v-for="dict in genderOptions" :key="dict.enumCode" :label="dict.enumCode">{{ dict.description
                  }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="民族" prop="nation">
                <el-select v-model="form.nation" placeholder="请选择民族">
                  <el-option v-for="dict in nationOptions" :key="dict.enumCode" :label="dict.description"
                    :value="dict.enumCode"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="出生日期" prop="birthDate">
                <el-date-picker clearable v-model="form.birthDate" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择出生日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="证件类型" prop="cardType">
                <el-select v-model="form.cardType" placeholder="请选择证件类型">
                  <el-option v-for="dict in cardTypeOptions" :key="dict.enumCode" :label="dict.description"
                    :value="dict.enumCode"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="身份证号" prop="cardId">
                <el-input v-model="form.cardId" placeholder="请输入证件号码" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="手机" prop="mobilePhone">
                <el-input v-model="form.mobilePhone" placeholder="请输入手机" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="个人邮箱" prop="personalEmail">
                <el-input v-model="form.personalEmail" placeholder="请输入个人邮箱" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="最高学历" prop="education">
                <el-select v-model="form.education" placeholder="请选择学历">
                  <el-option v-for="dict in educationOptions" :key="dict.enumCode" :label="dict.description"
                    :value="dict.enumCode"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="婚姻">
                <el-radio-group v-model="form.maritalStatus">
                  <el-radio v-for="dict in maritalStatusOptions" :key="dict.enumCode" :label="dict.enumCode">{{
                    dict.description }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="20">
              <el-form-item label="住址" prop="homeAddress">
                <el-input v-model="form.homeAddress" placeholder="请输入家庭住址" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider content-position="center">HR设置</el-divider>
          <!-- <el-row> -->
          <!-- <el-col :span="12">
              <el-form-item label="员工编号" prop="employeeNo">
                <el-input
                  v-model="form.employeeNo"
                  placeholder="请输入员工编号"
                />
              </el-form-item>
            </el-col> -->
          <!-- </el-row> -->
          <!-- <el-row> -->
          <!-- <el-col :span="12">
              <el-form-item label="入职类别" prop="entryType">
                <el-select
                  v-model="form.entryType"
                  placeholder="请选择入职类别"
                >
                  <el-option
                    v-for="dict in entryTypeOptions"
                    :key="dict.enumCode"
                    :label="dict.description"
                    :value="dict.enumCode"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
          <el-row>
            <el-col :span="12">
              <el-form-item label="员工类型" prop="emplType">
                <el-select v-model="form.emplType" placeholder="请选择员工类型">
                  <el-option v-for="dict in emplTypeOptions" :key="dict.enumCode" :label="dict.description"
                    :value="dict.enumCode"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="12">
              <el-form-item label="入职公司" prop="orgId">
                <el-input v-model="form.orgId" placeholder="请输入入职公司" />
              </el-form-item>
            </el-col> -->
            <!-- </el-row>
          <el-row> -->
            <el-col :span="12">
              <el-form-item label="入职部门" prop="deptId">
                <el-select v-model="form.deptId" placeholder="请选择入职部门">
                  <el-option v-for="dict in deptIdOptions" :key="dict.deptId" :label="dict.deptName"
                    :value="dict.deptId"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="入职岗位" prop="positionId">
                <el-select v-model="form.positionId" placeholder="请选择入职岗位">
                  <el-option v-for="dict in positionIdOptions" :key="dict.postId" :label="dict.postName"
                    :value="dict.postId"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="上级主管" prop="supervisor">
                <el-select v-model="form.supervisor" placeholder="请选择上级主管">
                  <el-option v-for="dict in supervisorOptions" :key="dict.partyId" :label="dict.firstName"
                    :value="dict.partyId"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="入职日期" prop="entryDate">
                <el-date-picker clearable v-model="form.entryDate" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择入职日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否试用期">
                <el-radio-group v-model="form.isProbation">
                  <el-radio v-for="dict in isProbationOptions" :key="dict.enumCode" :label="dict.enumCode">{{
                    dict.description }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="试用期" prop="probationPeriod">
                <el-input-number v-model="form.probationPeriod" placeholder="请输入试用期" /> 月
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="首次工作日期" prop="joinWorkTime">
                <el-date-picker clearable v-model="form.joinWorkTime" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择首次参加工作日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="工作地点" prop="workPlace">
                <el-input
                  v-model="form.workPlace"
                  placeholder="请输入工作地点"
                />
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row> -->
          <!-- <el-col :span="12">
              <el-form-item label="公司电话" prop="telephone">
                <el-input v-model="form.telephone" placeholder="请输入电话" />
              </el-form-item>
            </el-col> -->
          <!-- </el-row>
          <el-row> -->
          <!-- <el-col :span="12">
              <el-form-item label="公司邮箱" prop="mail">
                <el-input v-model="form.mail" placeholder="请输入邮箱" />
              </el-form-item>
            </el-col> -->
          <!-- <el-col :span="12">
              <el-form-item label="头像">
                <image-upload v-model="form.imageData" />
              </el-form-item>
            </el-col> -->
          <!-- </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="证件到期日期" prop="cardDueDate">
                <el-input
                  v-model="form.cardDueDate"
                  placeholder="请输入证件到期日期"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="籍贯" prop="nativePlace">
                <el-input v-model="form.nativePlace" placeholder="请输入籍贯" />
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="现居住地" prop="residentialAddress">
                <el-input
                  v-model="form.residentialAddress"
                  placeholder="请输入现居住地"
                />
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="政治面貌" prop="politicStatus">
                <el-select
                  v-model="form.politicStatus"
                  placeholder="请选择政治面貌"
                >
                  <el-option
                    v-for="dict in politicStatusOptions"
                    :key="dict.enumCode"
                    :label="dict.description"
                    :value="dict.enumCode"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="紧急联系人姓名" prop="emergencyPerson">
                <el-input
                  v-model="form.emergencyPerson"
                  placeholder="请输入紧急联系人姓名"
                />
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="紧急联系人电话" prop="emergencyPhone">
                <el-input
                  v-model="form.emergencyPhone"
                  placeholder="请输入紧急联系人电话"
                />
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="基本工资" prop="basicSalary">
                <el-input
                  v-model="form.basicSalary"
                  placeholder="请输入基本工资"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="绩效工资" prop="performanceSalary">
                <el-input
                  v-model="form.performanceSalary"
                  placeholder="请输入绩效工资"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="员工银行卡" prop="employeeCardNumbers">
                <el-input
                  v-model="form.employeeCardNumbers"
                  placeholder="请输入员工银行卡"
                />
              </el-form-item>
            </el-col> -->
          <el-divider content-position="center">合同信息</el-divider>
          <el-row>
            <el-col :span="12">
              <el-form-item label="合同类型" prop="contractType">
                <el-select v-model="form.contractType" placeholder="请选择合同类型">
                  <el-option v-for="dict in contractTypeOptions" :key="dict.enumCode" :label="dict.description"
                    :value="dict.enumCode"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同签订日期" prop="signContractDate">
                <el-date-picker clearable v-model="form.signContractDate" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择合同签订日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="合同期" prop="contractTerm">
                <el-input v-model="form.contractTerm" placeholder="请输入合同期" />
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-row> -->
          <!-- <el-col :span="12">
              <el-form-item label="入职状态" prop="entryStatusId">
                <el-select
                  v-model="form.entryStatusId"
                  placeholder="请选择入职状态"
                >
                  <el-option
                    v-for="dict in entryStatusIdOptions"
                    :key="dict.enumCode"
                    :label="dict.description"
                    :value="dict.enumCode"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
          <el-divider content-position="center">附件信息</el-divider>
          <el-row>
            <el-col :span="12">
              <el-form-item label="附件">
                <file-upload v-model="form.affixFilePath" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <!-- <el-col :span="12">
              <el-form-item label="流程状态" prop="flowStatus">
                <el-select
                  v-model="form.flowStatus"
                  placeholder="请选择流程状态"
                >
                  <el-option
                    v-for="dict in flowStatusOptions"
                    :key="dict.enumCode"
                    :label="dict.description"
                    :value="dict.enumCode"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
            <el-col :span="12">
              <el-form-item label="审批人" prop="approver">
                <LoadUserSelect :placeholder="'请选择审批人'" @getSelectedCourt="getSelectedApprover"></LoadUserSelect>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item size="large" align="center">
                <el-button type="primary" @click="saveForm">保 存</el-button>
                <el-button type="primary" @click="submitForm">提 交</el-button>
                <el-button type="danger" @click="close">关闭</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>

      <el-card class="Empl_entry_detail" v-if="detailFlag">
        <div slot="header" class="clearfix">
          <span>入职办理申请</span>
          <el-button style="float: right; padding: 3px 0" type="text" @click="edit">编辑</el-button>
          <!-- <el-button v-if="applyFlag" style="float: right; padding: 3px 0" type="text" @click="edit">编辑</el-button> -->
        </div>
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="申请日期" prop="applyDate">
                <span>{{ form.applyDate }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="申请人" prop="applyPartyId">
                <span>{{ form.applyPartyId }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="员工编号" prop="partyId">
                <span>{{ form.partyId }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider content-position="center">员工信息</el-divider>
          <el-row>
            <el-col :span="12">
              <el-form-item label="姓名" prop="firstName">
                <span>{{ form.firstName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="性别" prop="gender">
                <span>{{ genderFormat(form) }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="民族" prop="nation">
                <span>{{ nationFormat(form) }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="出生日期" prop="birthDate">
                <span>{{ form.birthDate }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="证件类型" prop="cardType">
                <span>{{ cardTypeFormat(form) }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="身份证号" prop="cardId">
                <span>{{ form.cardId }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="手机" prop="mobilePhone">
                <span>{{ form.mobilePhone }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="个人邮箱" prop="personalEmail">
                <span>{{ form.personalEmail }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="最高学历" prop="education">
                <span>{{ educationFormat(form) }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="婚姻" prop="maritalStatus">
                <span>{{ maritalStatusFormat(form) }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="住址" prop="homeAddress">
                <span>{{ form.homeAddress }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider content-position="center">HR设置</el-divider>
          <el-row>
            <!-- <el-col :span="12">
              <el-form-item label="入职类别" prop="entryType">
                <span>{{ entryTypeFormat(form) }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row> -->
            <el-col :span="12">
              <el-form-item label="员工类型" prop="emplType">
                <span>{{ emplTypeFormat(form) }}</span>
              </el-form-item>
            </el-col>
            <!-- </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="入职公司" prop="orgId">
                <span>{{ form.orgId }}</span>
              </el-form-item>
            </el-col> -->
            <el-col :span="12">
              <el-form-item label="入职部门" prop="deptId">
                <span>{{ deptIdFormat(form) }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="入职岗位" prop="positionId">
                <span>{{ positionIdFormat(form) }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="上级主管" prop="supervisor">
                <span>{{ supervisorFormat(form) }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="入职日期" prop="entryDate">
                <span>{{ form.entryDate }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否试用期" prop="isProbation">
                <span>{{ isProbationFormat(form) }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="试用期" prop="probationPeriod">
                <span>{{ form.probationPeriod }} 个月 </span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="首次工作日期" prop="joinWorkTime">
                <span>{{ form.joinWorkTime }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="入职状态" prop="entryStatusId">
                <span>{{ entryStatusIdFormat(form) }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="工作地点" prop="workPlace">
                <span>{{ form.workPlace }}</span>
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="电话" prop="telephone">
                <span>{{ form.telephone }}</span>
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="邮箱" prop="mail">
                <span>{{ form.mail }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="头像" prop="imageData">
                <span>{{ form.imageData }}</span>
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="证件到期日期" prop="cardDueDate">
                <span>{{ form.cardDueDate }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="籍贯" prop="nativePlace">
                <span>{{ form.nativePlace }}</span>
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="现居住地" prop="residentialAddress">
                <span>{{ form.residentialAddress }}</span>
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="政治面貌" prop="politicStatus">
                <span>{{ politicStatusFormat(form) }}</span>
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="紧急联系人姓名" prop="emergencyPerson">
                <span>{{ form.emergencyPerson }}</span>
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="紧急联系人电话" prop="emergencyPhone">
                <span>{{ form.emergencyPhone }}</span>
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="基本工资" prop="basicSalary">
                <span>{{ form.basicSalary }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="绩效工资" prop="performanceSalary">
                <span>{{ form.performanceSalary }}</span>
              </el-form-item>
            </el-col>
          </el-row> -->
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="员工银行卡" prop="employeeCardNumbers">
                <span>{{ form.employeeCardNumbers }}</span>
              </el-form-item>
            </el-col> -->
          <el-divider content-position="center">合同信息</el-divider>
          <el-row>
            <el-col :span="12">
              <el-form-item label="合同类型" prop="contractType">
                <span>{{ contractTypeFormat(form) }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同签订日期" prop="signContractDate">
                <span>{{ form.signContractDate }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="合同期" prop="contractTerm">
                <span>{{ form.contractTerm }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider content-position="center">附件信息</el-divider>
          <el-row>
            <el-col :span="20">
              <el-form-item label="附件" prop="affixFilePath">
                <span>{{ form.affixFilePath }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="流程状态" prop="flowStatus">
                <span>{{ flowStatusFormat(form) }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="审批人" prop="approver">
                <span>{{ approverFormat(form) }}</span>
              </el-form-item>
            </el-col>
          </el-row> -->
          <el-row>
            <el-col :span="24" v-if="applyFlag">
              <el-form-item size="large" align="center">
                <el-button type="primary" @click="saveForm">保 存</el-button>
                <el-button type="primary" @click="submitForm">提 交</el-button>
                <el-button type="danger" @click="close">关闭</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <!-- 审批组件 -->
      <approve v-if="approveFlag"></approve>
    </el-col>
  </div>
</template>

<script>
import LoadUserSelect from "@/components/LoadUserSelect";
// person enum api
import { getPersonEnum } from "@/api/ehr/person";
import {
  addEmpl_entry,
  updateEmpl_entry,
  approvalEmpl_entry,
  getEmpl_entry,
} from "@/api/ehr/empl_entry";
import { getBusinessLog } from "@/api/busi/log";
import { getProcessVariables } from "@/api/workflow/definition";

// 审批组件
import Approve from "@/components/Approve";

export default {
  components: { LoadUserSelect, Approve },
  name: "Empl_entry_apply",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 人员字典
      personOptions: [],
      // 审批人时间范围
      daterangeApplyDate: [],
      // 入职申请人业务字典
      applyPartyIdOptions: [],
      // 员工ID业务字典
      partyIdOptions: [],
      // 性别业务字典
      genderOptions: [],
      // 民族业务字典
      nationOptions: [],
      // 证件类型业务字典
      cardTypeOptions: [],
      // 入职类别业务字典
      entryTypeOptions: [],
      // 员工类型业务字典
      emplTypeOptions: [],
      // 入职部门业务字典
      deptIdOptions: [],
      // 入职岗位业务字典
      positionIdOptions: [],
      // 职级业务字典
      bandLevelOptions: [],
      // 是否试用期业务字典
      isProbationOptions: [],
      // 上级主管业务字典
      supervisorOptions: [],
      // 学历（最高）业务字典
      educationOptions: [],
      // 政治面貌业务字典
      politicStatusOptions: [],
      // 婚姻状况业务字典
      maritalStatusOptions: [],
      // 合同类型业务字典
      contractTypeOptions: [],
      // 入职状态业务字典
      entryStatusIdOptions: [],
      // 流程状态业务字典
      flowStatusOptions: [],
      // 审批人业务字典
      approverOptions: [],
      // 操作标识,用于区分是新增还是修改
      updateFlag: false,
      // 操作标识,用于区分是详情
      detailFlag: false,
      // 操作标识,用于区分编辑状态
      editFlag: true,
      // 业务申请标识
      applyFlag: true,
      // 业务审批标识
      approveFlag: false,

      // 表单参数
      form: {},
      // 表单校验
      rules: {
        applyDate: [
          { required: true, message: "申请日期不能为空", trigger: "blur" },
        ],

        partyId: [
          { required: true, message: "员工ID不能为空", trigger: "change" },
        ],

        firstName: [
          { required: true, message: "姓名不能为空", trigger: "blur" },
        ],

        gender: [{ required: true, message: "性别不能为空", trigger: "blur" }],

        cardId: [
          { required: true, message: "证件号码不能为空", trigger: "blur" },
        ],

        mobilePhone: [
          { required: true, message: "手机不能为空", trigger: "blur" },
        ],
        deptId: [
          { required: true, message: "入职部门不能为空", trigger: "blur" },
        ],
        positionId: [
          { required: true, message: "入职岗位不能为空", trigger: "blur" },
        ],
        entryDate: [
          { required: true, message: "入职日期不能为空", trigger: "blur" },
        ],

        supervisor: [
          { required: true, message: "上级主管不能为空", trigger: "change" },
        ],

        approver: [
          { required: true, message: "审批人不能为空", trigger: "change" },
        ],
      },
    };
  },
  created() {
    this.reset();
    // 为申请时间默认赋值
    this.form.applyDate = this.parseTime(new Date(), "{y}-{m}-{d} {h}:{i}:{s}");
    // 为申请人默认值
    this.form.partyId = this.$store.state.user.partyId;
    // 审批人默认值
    this.form.approver = this.$store.state.user.defaultApprover;
    // 人员字典
    getPersonEnum().then((response) => {
      this.personOptions = response.data;
    });
    // 员工ID业务字典
    this.getEntityDicts("person:partyId:firstName").then((response) => {
      this.partyIdOptions = response.data;
    });
    // 性别业务字典
    this.getEnumDicts("PERSON_GENDER").then((response) => {
      this.genderOptions = response.data;
    });
    // 民族业务字典
    this.getEnumDicts("NATION").then((response) => {
      this.nationOptions = response.data;
    });
    // 证件类型业务字典
    this.getEnumDicts("PERSON_CARD_TYPE").then((response) => {
      this.cardTypeOptions = response.data;
    });
    // 入职类别业务字典
    this.getEnumDicts("EMPL_ENTRY_TYPE").then((response) => {
      this.entryTypeOptions = response.data;
    });
    // 员工类型业务字典
    this.getEnumDicts("EMPL_TYPE").then((response) => {
      this.emplTypeOptions = response.data;
    });
    // 入职部门业务字典
    this.getEntityDicts("sysDept:deptId:deptName").then((response) => {
      this.deptIdOptions = response.data;
      this.deptIdOptions.forEach((item, index) => {
        item.deptId = item.deptId + ""
      });
    });
    // 入职岗位业务字典
    this.getEntityDicts("sysPost:postId:postName").then((response) => {
      this.positionIdOptions = response.data;
      this.positionIdOptions.forEach((item, index) => {
        item.postId = item.postId + ""
      });
    });
    // 是否试用期业务字典
    this.getEnumDicts("YES_NO").then((response) => {
      this.isProbationOptions = response.data;
    });
    // 上级主管业务字典
    this.getEntityDicts("person:partyId:firstName").then((response) => {
      this.supervisorOptions = response.data;
    });
    // 学历（最高）业务字典
    this.getEnumDicts("PERSON_EDUCATION").then((response) => {
      this.educationOptions = response.data;
    });
    // 政治面貌业务字典
    this.getEnumDicts("PERSON_POLITIC").then((response) => {
      this.politicStatusOptions = response.data;
    });
    // 婚姻状况业务字典
    this.getEnumDicts("PERSON_MARITAL").then((response) => {
      this.maritalStatusOptions = response.data;
    });
    // 合同类型业务字典
    this.getEnumDicts("EMPL_CONTRACT_TYPE").then((response) => {
      this.contractTypeOptions = response.data;
    });
    // 入职状态业务字典
    this.getEnumDicts("FLOW_STATUS").then((response) => {
      this.entryStatusIdOptions = response.data;
    });
    // 流程状态业务字典
    this.getEnumDicts("FLOW_STATUS").then((response) => {
      this.flowStatusOptions = response.data;
    });
    // 审批人业务字典
    this.getEntityDicts("person:partyId:firstName").then((response) => {
      this.approverOptions = response.data;
    });
    var procInsId = this.$route.query && this.$route.query.procInsId;
    if (procInsId) {
      this.editFlag = false;
      this.detailFlag = true;
      // 业务申请标识
      this.applyFlag = false;
      // 审批标识
      this.approveFlag = true;
    }
    var taskId = this.$route.query && this.$route.query.taskId;
    // 获取表单参数
    this.getApproveFormParams(taskId, procInsId);

    //为选项默认赋值
    if (this.form.cardType == null) {
      // this.form.cardType = "IDcard"
      // this.form.cardType = this.cardTypeOptions[0].description
    }
    // if (this.form.entryType == null) {
    //   this.form.entryType = this.entryTypeOptions[0]
    // }
    if (this.form.entryDate == null) {
      this.form.entryDate = this.parseTime(new Date(), "{y}-{m}-{d}");
    }
      // if (this.form.emplType == null) {
      //   this.form.emplType = this.emplTypeOptions[0]
      // }
  },
  mounted() {
    // this.form.nation = this.nationOptions[0].enumCode;
    // this.form.cardType = this.cardTypeOptions[0].enumCode;
  },
  computed: {
    userInfo() {
      return this.$store.state.user; //当前登录用户信息
    },
  },
  methods: {
    // 获取审批表单变量
    getApproveFormParams(taskId, procInsId) {
      // 1.优先从工作流的参数中获取表单信息,流程任务重获取变量表单
      if (taskId) {
        getProcessVariables(taskId).then((res) => {
          this.form = res.data.businessMap;
        });
        // getProcessVariables(taskId).then((res) => {
        //   console.info("businessMap:" + JSON.stringify(res.data.businessMap));
        //   // 获取 入职审批记录ID entryApplyId
        //   var entryApplyId = res.data.businessMap.entryApplyId;
        //   getEmpl_entry(entryApplyId).then((response) => {
        //     this.form = response.data;
        //   });
        //   //   this.form = res.data.businessMap;
        // });
      } else {
        // 2.从业务流水表获取工作流表单参数
        getBusinessLog(procInsId).then((response) => {
          if (response.data) {
            this.form = JSON.parse(response.data.busiContentJson);
          }
        });
      }
    },

    // 审批人选择赋值
    getSelectedApprover(e) {
      this.form.approver = e;
    },
    // 人员字典转换
    personFormat(row, column) {
      let val = null;
      this.personOptions.forEach((item, index) => {
        if (row.partyId === item.partyId) {
          val = item.name;
        }
      });
      return val;
    },
    // 审批人字典转换
    approverFormat(row, column) {
      let val = null;
      this.personOptions.forEach((item, index) => {
        if (row.approver === item.partyId) {
          val = item.name;
        }
      });
      return val;
    },
    partyIdFormat(row, column) {
      let val = null;
      this.partyIdOptions.forEach((item, index) => {
        if (row.partyId === item.partyId) {
          val = item.firstName;
        }
      });
      return val;
    },
    genderFormat(row, column) {
      let val = null;
      this.genderOptions.forEach((item, index) => {
        if (row.gender === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    nationFormat(row, column) {
      let val = null;
      this.nationOptions.forEach((item, index) => {
        if (row.nation === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    cardTypeFormat(row, column) {
      let val = null;
      this.cardTypeOptions.forEach((item, index) => {
        if (row.cardType === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    entryTypeFormat(row, column) {
      let val = null;
      this.entryTypeOptions.forEach((item, index) => {
        if (row.entryType === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    emplTypeFormat(row, column) {
      let val = null;
      this.emplTypeOptions.forEach((item, index) => {
        if (row.emplType === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    deptIdFormat(row, column) {
      let val = null;
      this.deptIdOptions.forEach((item, index) => {
        if (row.deptId === item.deptId) {
          val = item.deptName;
        }
      });
      return val;
    },
    positionIdFormat(row, column) {
      let val = null;
      this.positionIdOptions.forEach((item, index) => {
        if (row.positionId === item.postId) {
          val = item.postName;
        }
      });
      return val;
    },
    isProbationFormat(row, column) {
      let val = null;
      this.isProbationOptions.forEach((item, index) => {
        if (row.isProbation === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    supervisorFormat(row, column) {
      let val = null;
      this.supervisorOptions.forEach((item, index) => {
        if (row.supervisor === item.partyId) {
          val = item.firstName;
        }
      });
      return val;
    },
    educationFormat(row, column) {
      let val = null;
      this.educationOptions.forEach((item, index) => {
        if (row.education === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    politicStatusFormat(row, column) {
      let val = null;
      this.politicStatusOptions.forEach((item, index) => {
        if (row.politicStatus === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    maritalStatusFormat(row, column) {
      let val = null;
      this.maritalStatusOptions.forEach((item, index) => {
        if (row.maritalStatus === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    contractTypeFormat(row, column) {
      let val = null;
      this.contractTypeOptions.forEach((item, index) => {
        if (row.contractType === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    entryStatusIdFormat(row, column) {
      let val = null;
      this.entryStatusIdOptions.forEach((item, index) => {
        if (row.entryStatusId === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    flowStatusFormat(row, column) {
      let val = null;
      this.flowStatusOptions.forEach((item, index) => {
        if (row.flowStatus === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    approverFormat(row, column) {
      let val = null;
      this.approverOptions.forEach((item, index) => {
        if (row.approver === item.partyId) {
          val = item.firstName;
        }
      });
      return val;
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        entryApplyId: null,
        applyDate: null,
        applyPartyId: null,
        partyId: null,
        firstName: null,
        gender: null,
        nation: null,
        birthDate: null,
        cardType: null,
        cardId: null,
        mobilePhone: null,
        personalEmail: null,
        employeeNo: null,
        entryType: null,
        emplType: null,
        orgId: null,
        deptId: null,
        positionId: null,
        bandLevel: null,
        entryDate: null,
        isProbation: "0",
        probationPeriod: null,
        workPlace: null,
        supervisor: null,
        telephone: null,
        mail: null,
        imageData: null,
        cardDueDate: null,
        nativePlace: null,
        residentialAddress: null,
        homeAddress: null,
        education: null,
        politicStatus: null,
        maritalStatus: "0",
        health: null,
        emergencyPerson: null,
        emergencyPhone: null,
        joinWorkTime: null,
        basicSalary: null,
        performanceSalary: null,
        employeeCardNumbers: null,
        contractType: null,
        signContractDate: null,
        contractTerm: null,
        entryStatusId: null,
        affixFilePath: null,
        flowInstId: null,
        flowStatus: null,
        approver: null,
        lastUpdatedStamp: null,
        lastUpdatedTxStamp: null,
        createdStamp: null,
        createdTxStamp: null,
      };
      //this.resetForm("form");
    },

    /** 保存按钮 */
    saveForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.loading = true;
          if (this.form.entryApplyId != null && this.updateFlag) {
            updateEmpl_entry(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
            });
          } else {
            addEmpl_entry(this.form).then((response) => {
              this.form.entryApplyId = response.resultMap.entryApplyId;
              this.$modal.msgSuccess("新增成功");
              this.open = false;
            });
          }
          this.loading = false;

          this.editFlag = false;
          this.detailFlag = true;
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.loading = true;

          approvalEmpl_entry(this.form).then((response) => {
            this.$modal.msgSuccess("申请提交成功！");
            this.open = false;
          });
          this.loading = false;

          this.close();
        }
      });
    },

    /** 编辑 */
    edit() {
      this.editFlag = true;
      this.detailFlag = false;
      this.updateFlag = true;
    },
    resetForm() {
      this.$refs["form"].resetFields();
    },
    close() {
      this.$tab.closePage();
    },
  },
};
</script>
